//
//  PushForStrategyCell.m
//  HYHOME
//
//  Created by cjy on 16/3/3.
//  Copyright © 2016年 Mac. All rights reserved.
//

#import "PushForStrategyCell.h"

#import "ModelS.h"
#import "UIImageView+WebCache.h"
#import "DKNightVersion.h"
@implementation PushForStrategyCell



- (void)dealloc{
    
    [_main_body release];
    [_url release];
    [super dealloc];




}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
      self.main_body =[[ UILabel alloc]init];
        
        [self.contentView addSubview:self.main_body];
        
        self.url = [[UIImageView alloc]init];
        
        [self.contentView addSubview:self.url];
        
        [self.main_body release];
        [self.url release];
        
    }

    return self;


}



- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    
}


+ (CGFloat)heightForLabel:(NSString *)text{
    
    CGRect rect = [text boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 40, 0) options: NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil];
    
    return rect.size.height;
}


+ (CGFloat)heightForCell:(ModelS *)model{
    
    CGFloat height =  [PushForStrategyCell heightForLabel:model.main_body];
    
    
    if (!model.url) {
        
        return height + 20 + 15;
    }
    return height + 20 + 15 + 200;
}


- (void)passmodel:(ModelS *)model{
    

    self.main_body.text = model.main_body;
    self.main_body.numberOfLines = 0;
    self.main_body.font = [UIFont systemFontOfSize:13];
    self.main_body.dk_textColorPicker = DKColorWithRGB(0x000000, 0xc6e2ef);
    
    
    
    if (!model.url) {
        self.url.frame = CGRectMake(0, 0, 0, 0);
        self.main_body.frame = CGRectMake(10, 15, self.contentView.frame.size.width-20, [[self class] heightForLabel:self.main_body.text]);    // 自适应
        
    }else{
        self.main_body.frame = CGRectMake(10, 15 + 200, self.contentView.frame.size.width-20, [[self class] heightForLabel:self.main_body.text]);    // 自适应
        
        self.url.frame = CGRectMake(40, 20, self.frame.size.width - 80, 200);
        
        [self.url sd_setImageWithURL:[NSURL URLWithString:model.url] placeholderImage:[UIImage imageNamed:@"jz"]];
        
    }

    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
